<?php
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Dcat\Admin\Admin;

Admin::routes();

Route::group([
    'prefix'     => config('admin.route.prefix'),
    'namespace'  => config('admin.route.namespace'),
    'middleware' => config('admin.route.middleware'),
], function (Router $router) {
    $router->resource('auth/users', 'UserController')->names('auth.users');


    // # 登录
    $router->get('error', 'PageController@error')->name('auth.error');
    $router->get('tip', 'PageController@sso_logout_witherror')->name('auth.sso_logout_witherror');

    $router->get('auth/login', 'AuthController@get_local_login')->name('login');
    $router->get('auth/login_by_account', 'AuthController@loginByAccount')->name('auth.get.loginByAccount');
    $router->post('auth/login', 'AuthController@post_local_login')->name('auth.post.login');
    $router->get('auth/sso_login', 'AuthController@sso_login_callback')->name('auth.sso.login');

    $router->get('auth/logout', 'AuthController@logout')->name('logout');
    $router->get('auth/sso_logout', 'AuthController@sso_logout')->name('auth.sso.logout');
    $router->get('auth/local_logout', 'AuthController@local_logout')->name('auth.local.logout');

    $router->get('auth/sso_test', 'AuthController@sso_test');

    // $router->resource('auth/users', 'UserController', ['except' => ['destroy']])->names('users');
    $router->get('/index', 'HomeController@index')->name('home');

    # 操作日志
    $router->resource('operation_logs', 'AdminOperationLogController', ['only' => ['index']])->names('operation_logs');

    $router->match(['POST', 'GET'], 'configs', 'ConfigController@index')->name('config');

    $router->match(['POST', 'PUT'], 'file_handle', 'FileController@handle')->name('files.upload');

    $router->get('login_moni/{gid}', 'AuthController@login_moni');

});

Route::group([
    'prefix'     => config('admin.route.prefix'),
    'namespace'  => config('admin.route.namespace'),
    'middleware' => config('admin.route.middleware_remember_url'),
], function (Router $router) {
    $router->get('departments', 'DepartmentsController@index')->name('department.index');
    $router->get('dj_departments', 'DjDepartmentsController@index')->name('dj_department.index');

    $router->post('department_file_uploader/submit_audit', 'DepartmentFileUploaderController@submitAudit')->name('department.file.submit_audit');
    $router->get('department_file_uploader', 'DepartmentFileUploaderController@index')->name('department.file.uploader');
    
    # 文件的下载和读取
    $router->get('dfile/{id}/download', 'DepartmentFileUploaderController@downloadFile')->name('department.file.download');
    $router->match(['POST', 'GET'], 'dfile/{id}/read', 'DepartmentFileUploaderController@readFile')->name('department.file.read');

    $router->get('zipdwfile', 'DepartmentFileUploaderController@downloadDwAllFiles')->name('department.zip');

});
